//
//  ShoppingHotContentTableViewCell.m
//  quxiangtao
//
//  Created by xbmios on 2018/6/27.
//  Copyright © 2018年 shanhaijin. All rights reserved.
//

#import "ShoppingHotContentTableViewCell.h"

@interface ShoppingHotContentTableViewCell ()

// 商品图片
@property (strong, nonatomic) UIImageView *iconImageV;
// 商品标题
@property (strong, nonatomic) UILabel *titleL;
// 商品现价
@property (strong, nonatomic) UILabel *priceL;
@property (strong, nonatomic) UILabel *priceMoneyL;
// 销售量
@property (strong, nonatomic) UILabel *sellOutL;
@property (strong, nonatomic) UILabel *sellOutNumberL;
//商品原价
@property (strong, nonatomic) UILabel *orignalPriceL;
@property (strong, nonatomic) UILabel *orignalPriceMoneyL;
// 优惠券
@property (strong, nonatomic) UIImageView *vouchersIV;
@property (strong, nonatomic) UILabel *voucherMoneyL;

@property (strong, nonatomic) UIView *lineV;

@end

@implementation ShoppingHotContentTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self.contentView addSubview:self.iconImageV];
        [self.contentView addSubview:self.titleL];
        [self.contentView addSubview:self.orignalPriceL];
        [self.contentView addSubview:self.orignalPriceMoneyL];
        [self.contentView addSubview:self.priceL];
        [self.contentView addSubview:self.priceMoneyL];
        [self.contentView addSubview:self.vouchersIV];
        [self.contentView addSubview:self.voucherMoneyL];
        [self.contentView addSubview:self.sellOutL];
        [self.contentView addSubview:self.sellOutNumberL];
        [self.contentView addSubview:self.lineV];
        
        self.voucherMoneyL.hidden = YES;
        self.vouchersIV.hidden = YES;
        
    }
    
    return self;
}

//#pragma mark -搜索界面cell赋值
//- (void)setSearchModel:(SearchResultModel *)searchModel {
//    
//    _searchModel = searchModel;
//    
//    self.titleL.text = searchModel.title;
//    
//    NSString *priceStr = [NSString stringWithFormat:@"￥%@", searchModel.zk_final_price];
//    NSMutableAttributedString *attribtueStr = [[NSMutableAttributedString alloc] initWithString:priceStr];
//    [attribtueStr addAttribute:NSFontAttributeName value:Font(20) range:NSMakeRange(0, 1)];
//    [attribtueStr addAttribute:NSFontAttributeName value:Font(24) range:NSMakeRange(1, priceStr.length - 1)];
//    self.priceMoneyL.attributedText = attribtueStr;
////
////    NSString *price = [NSString stringWithFormat:@"￥%@", searchModel.zk_final_price];
////    NSMutableAttributedString *priceAttributeStr = [[NSMutableAttributedString alloc] initWithString:price];
////    [priceAttributeStr addAttribute:NSFontAttributeName value:Font(20) range:NSMakeRange(0, 1)];
////    [priceAttributeStr addAttribute:NSFontAttributeName value:Font(30) range:NSMakeRange(1, price.length - 1)];
////    //    [priceAttributeStr addAttribute:NSExpansionAttributeName value:@0.2 range:NSMakeRange(0, price.length)];
////    self.salePriceL.attributedText = priceAttributeStr;
////
////
////    NSString *oldPrice = [NSString stringWithFormat:@"￥%@", searchModel.goods_price];
////    NSDictionary *attributeDic = @{NSStrikethroughStyleAttributeName:[NSNumber numberWithInteger:NSUnderlineStyleSingle]};
////    NSMutableAttributedString *oldPirceAttributeStr = [[NSMutableAttributedString alloc] initWithString:oldPrice attributes:attributeDic];
////    self.originalPriceL.attributedText = oldPirceAttributeStr;
////
////    [self.goodIV sd_setImageWithURL:[NSURL URLWithString:searchModel.pict_url]];
//    
//    [self.iconImageV sd_setImageWithURL:[NSURL URLWithString:searchModel.pict_url]];
////
////    self.sellOutL.text = [NSString stringWithFormat:@"已售：%@", searchModel.volume];
//    
//    self.orignalPriceL.text = [NSString stringWithFormat:@"售出：%@", searchModel.volume];
////
////    self.vouchMoneyL.font = Font(24);
////    self.vouchMoneyL.text = searchModel.coupon_info;
////
////    self.integDiscountL.text = [NSString stringWithFormat:@"抵扣比例%@", searchModel.commission_rate];
////
////    [self.ticketL sizeToFit];
////    [self.integDiscountL sizeToFit];
//    
//}

#pragma mark -自营界面cell赋值
- (void)setModel:(SupportCategoryGoodListModel *)model {
    
    _model = model;
    
    __weak typeof(self) weakSelf = self;
    
    if (self.type == 1) {
        
        self.titleL.text = model.title;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        NSString *priceStr = [NSString stringWithFormat:@"￥%@", model.price];
        NSMutableAttributedString *attribtueStr = [[NSMutableAttributedString alloc] initWithString:priceStr];
        [attribtueStr addAttribute:NSFontAttributeName value:Font(20) range:NSMakeRange(0, 1)];
        [attribtueStr addAttribute:NSFontAttributeName value:Font(24) range:NSMakeRange(1, priceStr.length - 1)];
        self.priceMoneyL.attributedText = attribtueStr;
 
        self.orignalPriceMoneyL.text = [NSString stringWithFormat:@"%@件", model.repertory];
        
        NSString *str = nil;
        
        if ([model.goods_url hasPrefix:@"http://"] || [model.goods_url hasPrefix:@"https://"]) {
            
            str = model.goods_url;
       
        }else {
            
            str = [NSString stringWithFormat:@"http://%@",model.goods_url];
        }
        
        [self.iconImageV sd_setImageWithURL:[NSURL URLWithString:str]];
        
        self.orignalPriceL.text = @"剩余：";
        
        self.sellOutL.font = Font(24);
        self.sellOutNumberL.font = Font(24);
        
        // 不显示优惠券
        self.voucherMoneyL.hidden = YES;
        self.vouchersIV.hidden = YES;
//        self.orignalPriceMoneyL.hidden = YES;
        
        self.sellOutL.hidden = YES;
        self.sellOutNumberL.hidden = YES;
        
//        [self.sellOutNumberL mas_makeConstraints:^(MASConstraintMaker *make) {
//
//            make.right.mas_equalTo(weakSelf.contentView.mas_right).with.offset(-Margin);
//            make.bottom.mas_equalTo(weakSelf.iconImageV.mas_bottom).with.offset(-jisuan(10));
//
//        }];
        
//        [self.sellOutL mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.right.mas_equalTo(weakSelf.sellOutNumberL.mas_left).with.offset(jisuan(2));
//            make.bottom.mas_equalTo(weakSelf.iconImageV.mas_bottom).with.offset(-jisuan(10));
//
//        }];
        
    }else {

            // 显示优惠券
            self.vouchersIV.hidden = NO;
            self.voucherMoneyL.hidden = NO;
            self.orignalPriceMoneyL.hidden = NO;
            
            self.sellOutL.font = Font(20);
            self.sellOutNumberL.font = Font(20);
            
            
            [self.sellOutNumberL mas_makeConstraints:^(MASConstraintMaker *make) {
                make.right.mas_equalTo(weakSelf.contentView.mas_right).with.offset(-Margin);
                make.bottom.mas_equalTo(weakSelf.iconImageV.mas_bottom).with.offset(-jisuan(80));
                
            }];
            
            [self.sellOutL mas_makeConstraints:^(MASConstraintMaker *make) {
                make.right.mas_equalTo(weakSelf.sellOutNumberL.mas_left).with.offset(jisuan(2));
                make.bottom.mas_equalTo(weakSelf.iconImageV.mas_bottom).with.offset(-jisuan(80));
                
            }];
        
    }
    
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    __weak typeof(self) weakSelf = self;
    
    [self.iconImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.contentView.mas_left).with.offset(SmallMargin);
        make.centerY.mas_equalTo(weakSelf.contentView.mas_centerY);
        make.width.mas_equalTo(jisuan(180));
        make.height.mas_equalTo(jisuan(180));
        
    }];
    
    [self.titleL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.iconImageV.mas_right).with.offset(Margin);
        make.top.mas_equalTo(weakSelf.iconImageV.mas_top).with.offset(jisuan(10));
        make.right.mas_equalTo(weakSelf.contentView.mas_right).with.offset(-Margin);
        
    }];
    
    [self.priceL sizeToFit];
    [self.priceL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.titleL.mas_left);
        make.bottom.mas_equalTo(weakSelf.iconImageV.mas_bottom).with.offset(-jisuan(10));
        
    }];
    [self.priceMoneyL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.priceL.mas_right);
        make.centerY.mas_equalTo(weakSelf.priceL.mas_centerY);
        
    }];
    
    [self.orignalPriceL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.priceL.mas_left);
        make.bottom.mas_equalTo(weakSelf.priceL.mas_top).with.offset(-jisuan(12));
    }];
    [self.orignalPriceMoneyL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.orignalPriceL.mas_right);
        make.bottom.mas_equalTo(weakSelf.priceL.mas_top).with.offset(-jisuan(12));
    }];

//    [self.orignalPriceMoneyL mas_makeConstraints:^(MASConstraintMaker *make) {
//
//        make.left.mas_equalTo(weakSelf.priceL.mas_left);
//        make.bottom.mas_equalTo(weakSelf.priceL.mas_top).with.offset(-jisuan(12));
//    }];
    
    [self.vouchersIV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(weakSelf.contentView.mas_right).with.offset(-Margin);
        make.bottom.mas_equalTo(weakSelf.priceL.mas_bottom);
        make.width.mas_equalTo(jisuan(160));
        make.height.mas_equalTo(jisuan(60));
    }];
    
    [self.voucherMoneyL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.mas_equalTo(weakSelf.vouchersIV.mas_centerY);
        make.right.mas_equalTo(weakSelf.vouchersIV.mas_right).with.offset(-jisuan(60));
        make.width.mas_equalTo(jisuan(95));
        make.height.mas_equalTo(jisuan(60));
    }];

    [self.lineV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.contentView.mas_left);
        make.right.mas_equalTo(weakSelf.contentView.mas_right);
        make.bottom.mas_equalTo(weakSelf.contentView.mas_bottom);
        make.height.mas_equalTo(jisuan(2));
    }];
}

#pragma mark -lazy
- (UIImageView *)vouchersIV {
    
    if (!_vouchersIV) {
        
        _vouchersIV = [[UIImageView alloc] init];
        _vouchersIV.contentMode = UIViewContentModeScaleAspectFit;
        _vouchersIV.image = [UIImage imageNamed:@"vuochersBG"];
        
    }
    
    return _vouchersIV;
}

- (UILabel *)voucherMoneyL {
    
    if (!_voucherMoneyL) {
        
        _voucherMoneyL = [[UILabel alloc] init];
        _voucherMoneyL.textColor = Colorff0000;
        _voucherMoneyL.textAlignment = NSTextAlignmentCenter;
        
//        NSString *moneyStr = @"￥200";
//        NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc] initWithString:moneyStr];
//        [attributeStr addAttribute:NSFontAttributeName value:Font(20) range:NSMakeRange(0, 1)];
//        [attributeStr addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:jisuan(30)] range:NSMakeRange(1, moneyStr.length - 1)];
//        _voucherMoneyL.attributedText = attributeStr;
        
        [_voucherMoneyL sizeToFit];
        
    }
    
    return _voucherMoneyL;
}

- (UILabel *)orignalPriceL {
    
    if (!_orignalPriceL) {
        
        _orignalPriceL = [[UILabel alloc] init];
        _orignalPriceL.textColor = Color999999;
        _orignalPriceL.font = Font(20);
        _orignalPriceL.textAlignment = NSTextAlignmentLeft;
        
    }

    return _orignalPriceL;
}



- (UILabel *)orignalPriceMoneyL {
    
    if (!_orignalPriceMoneyL) {
        
        _orignalPriceMoneyL = [[UILabel alloc] init];
        _orignalPriceMoneyL.textColor = Color999999;
        _orignalPriceMoneyL.font = Font(20);
        _orignalPriceMoneyL.textAlignment = NSTextAlignmentLeft;
        
//        NSString *oldPrice = @"￥11288.00";
//        NSDictionary *attributeDic = @{NSStrikethroughStyleAttributeName:[NSNumber numberWithInteger:NSUnderlineStyleSingle]};
//        NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc] initWithString:oldPrice attributes:attributeDic];
//        _orignalPriceMoneyL.attributedText = attributeStr;
        
    }
    
    return _orignalPriceMoneyL;
}

- (UIImageView *)iconImageV {
    
    if (!_iconImageV) {
        
        _iconImageV = [[UIImageView alloc] init];
        _iconImageV.contentMode = UIViewContentModeScaleAspectFit;
        
        _iconImageV.backgroundColor = Colorf2f2f2;
        
    }
    
    return _iconImageV;
}
- (UILabel *)titleL {
    
    if (!_titleL) {
        
        _titleL = [[UILabel alloc] init];
        _titleL.numberOfLines = 2;
        _titleL.font = Font(24);
        _titleL.textColor = Color333333;
        _titleL.textAlignment = NSTextAlignmentLeft;
        
//        _titleL.text = @"Apple MacBook 苹果笔记本苹果笔记本苹果笔记本";
//
//        NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:_titleL.text];
//        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
//        [paragraphStyle setLineSpacing:jisuan(10)];
//        [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [_titleL.text length])];
//        _titleL.attributedText = attributedString;
//        _titleL.lineBreakMode = NSLineBreakByCharWrapping;
        
    }
    
    return _titleL;
}

- (UILabel *)priceL {
    
    if (!_priceL) {
    
        _priceL = [[UILabel alloc] init];
        _priceL.textAlignment = NSTextAlignmentLeft;
        _priceL.textColor = Color999999;
        _priceL.font = Font(24);
        _priceL.text = @"价格：";
        
    }
    
    return _priceL;
}

- (UILabel *)priceMoneyL {
    
    if (!_priceMoneyL) {
        
        _priceMoneyL = [[UILabel alloc] init];
//        _priceMoneyL.font = Font(24);
        _priceMoneyL.textAlignment = NSTextAlignmentLeft;
        _priceMoneyL.textColor = Colorff0000;
        
//        _priceMoneyL.text = @"￥11288.00";
//        NSString *priceStr = @"￥11288.00";
//        NSMutableAttributedString *attribtueStr = [[NSMutableAttributedString alloc] initWithString:priceStr];
//        [attribtueStr addAttribute:NSFontAttributeName value:Font(20) range:NSMakeRange(0, 1)];
//        [attribtueStr addAttribute:NSFontAttributeName value:Font(24) range:NSMakeRange(1, priceStr.length - 1)];
//        _priceMoneyL.attributedText = attribtueStr;
        
        
    }
    
    return _priceMoneyL;

}

- (UILabel *)sellOutL {
    
    if (!_sellOutL) {
        
        _sellOutL = [[UILabel alloc] init];
        _sellOutL.font = Font(24);
        _sellOutL.textAlignment = NSTextAlignmentLeft;
        _sellOutL.textColor = Color999999;
        _sellOutL.text = @"已售：";
        
    }
    
    return _sellOutL;
}

- (UILabel *)sellOutNumberL {
    
    if (!_sellOutNumberL) {
        
        _sellOutNumberL = [[UILabel alloc] init];
        _sellOutNumberL.font = Font(24);
        _sellOutNumberL.textAlignment = NSTextAlignmentLeft;
        _sellOutNumberL.textColor = Color999999;
        _sellOutNumberL.text = @"1000件";
        
    }
    
    return _sellOutNumberL;
    
}

- (UIView *)lineV {
    
    if (!_lineV) {
        
        _lineV = [[UIView alloc] init];
        _lineV.backgroundColor = Colordddddd;
    }
    return _lineV;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end

